import time
from src.db.db_provider import DBProvider
from src.db.db_agro_sample_management import create_agro_sample_management_table, create_agro_sample_management_table_csv
from src.utils.config_utils import DataConfigParser
from src.utils.loghelper import logHelper
from src.agro_sample_management import AGROSampleManagement

dbConfig_token = "dbConfig"
dbConfig_dbname_token = "dbname"
dbConfig_host_token = "host"
dbConfig_user_token = "user"
dbConfig_pwd_token = "pwd"

fileConfig_token = "fileConfig"
file_path_token = "FilePath"
interval_token = "interval"


class AGROSample(object):

    _host = None
    _user = None
    _pwd = None
    _db = None

    def process(self, file_path):
        # DBProvider().initial('localhost', 'qq', '123', 'AGRO_RS_DATA')
        DBProvider().initial(self._host, self._user, self._pwd, self._db)

        DBProvider().create_tables(create_agro_sample_management_table)
        DBProvider().create_tables(create_agro_sample_management_table_csv)

        agro_sample_management = AGROSampleManagement()
        agro_sample_management.analyze(file_path)

    def __init__(self):
        self._db = DataConfigParser().get_data_configuration(dbConfig_token, dbConfig_dbname_token)
        self._host = DataConfigParser().get_data_configuration(dbConfig_token, dbConfig_host_token)
        self._user = DataConfigParser().get_data_configuration(dbConfig_token, dbConfig_user_token)
        self._pwd = DataConfigParser().get_data_configuration(dbConfig_token, dbConfig_pwd_token)


def main_func():

    agro_sample_management = AGROSample()

    file_path = DataConfigParser().get_data_configuration(fileConfig_token, file_path_token)

    # interval = DataConfigParser().get_data_configuration(interval_token, interval_token)

    logHelper.set_log()
    logHelper.info("please put your in %s" % file_path)

    agro_sample_management.process(file_path)

    # while True:
    #     agro_sample_management.process(file_path)
    #     time.sleep(int(interval))


if __name__ == '__main__':
    main_func()